package com.yoomiito.app.utils;

import android.view.Gravity;
import android.widget.Toast;

import com.yoomiito.app.base.App;

public class YMToast {
    private static Toast mToast;
    public static void showText(String text) {
        Toast.makeText(App.getApplication(),text,Toast.LENGTH_SHORT).show();
    }

    public static void showCenterToast(String text){
        Toast mToast = Toast.makeText(App.getApplication(),text,Toast.LENGTH_SHORT);
        mToast.setGravity(Gravity.CENTER,0,0);
        mToast.show();
    }

    /**
     * 连续显示
     * @param text
     * @param time
     */
    public static void showText(String text,int time) {
        if (mToast==null){
            getCenterToast(text,time);
            mToast.show();
        }else {
            mToast.cancel();
            getCenterToast(text, time);
            mToast.show();
        }
    }

    private static void getCenterToast(String text,int time){
        mToast = Toast.makeText(App.getInstance(),text,time);
        mToast.setGravity(Gravity.CENTER,0,0);
    }
}
